package cfdt.common.encryptor;

import cfdt.tools.crypto.SecurityUtils;
import cfdt.common.exception.CodeException;
import org.jasypt.encryption.StringEncryptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component("SM4StringEncryptor")
public class SM4StringEncryptor implements StringEncryptor {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public String encrypt(String message) {
        try {
            return SecurityUtils.encryptSM4(message);
        } catch (CodeException e) {
            logger.error("加密异常", e);
        }
        return message;
    }

    @Override
    public String decrypt(String encryptedMessage) {
        try {
            return SecurityUtils.decryptSM4(encryptedMessage);
        } catch (CodeException e) {
            logger.error("解密异常", e);
        }
        return encryptedMessage;
    }

}
